/**
 * @author Bushra Nazir
 */
package com.es.controller;

import java.util.List;

import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import org.apache.log4j.Logger;

import com.es.business.contact.IContactBL;
import com.es.exception.business.ESException;
import com.es.model.BusinessContact;
import com.es.model.Client;
import com.es.model.Contact;
import com.es.model.Lead;
import com.es.util.ProjectConstant;
import com.es.util.ProjectUtility;

/**
 * @author Bushra
 *
 */
public class ContactController extends BaseController {
	
	private static final Logger log = Logger.getLogger(ContactController.class);
	
	private String tempVar;
	
	private IContactBL contactImpl;
	private Contact contact;
	private Lead lead;


	private List<SelectItem> contactTypeSelectItems;
	
	public void init(){
		
		log.info(" inside init()" );
		/*FacesContext fc = FacesContext.getCurrentInstance();
		lead = (Lead) fc.getExternalContext().getRequestMap().get(ProjectConstant.LEAD_TO_BE_CONVERTED_SESSION_KEY);
		*/
		
		FacesContext fc = FacesContext.getCurrentInstance();
		lead = (Lead) fc.getExternalContext().getSessionMap().get(ProjectConstant.LEAD_TO_BE_CONVERTED_SESSION_KEY);
	
		if (lead == null){
			
			log.info("lead is null in init()" );
		}else {
			
			log.info("lead id ::" + lead.getLeadId());
		}
		
	}
	
	
	public void initView(){
		
		contactTypeSelectItems = UtilityController.getContactTypeSelectItems();
		
	}
	
	
	
	public String createContact(){
		
		log.info("inside createContact()" );
		
		
		try{			
			
			contactImpl.createContact(contact, lead);	
			
			}catch (ESException e) {
			
			log.info(e.getMessage());
			
		}	
		
		return null;		
		
	}
	
	
	
	
	
	
	
	public String getTempVar() {
		
		init();
		initView();
		tempVar = "do-nothing-str";
		return tempVar;
	}

	public void setTempVar(String tempVar) {
		this.tempVar = tempVar;
	}
	
	
	public IContactBL getContactImpl() {
		log.info("getter called :: " + contactImpl);
		return contactImpl;
	}

	public void setContactImpl(IContactBL contactImpl) {
		log.info("setter called :: " + contactImpl);
		this.contactImpl = contactImpl;
	}

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public Lead getLead() {
		return lead;
	}

	public void setLead(Lead lead) {
		this.lead = lead;
	}


	public List<SelectItem> getContactTypeSelectItems() {
		return contactTypeSelectItems;
	}


	public void setContactTypeSelectItems(List<SelectItem> contactTypeSelectItems) {
		this.contactTypeSelectItems = contactTypeSelectItems;
	}



}
